<html>
<head>
  <meta HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=ISO-8859-1">
  <title>dualmean.m</title>
<link rel="stylesheet" type="text/css" href="../../m-syntax.css">
</head>
<body>
<code>
<span class=defun_kw>function</span>&nbsp;<span class=defun_out>m</span>=<span class=defun_name>dualmean</span>(<span class=defun_in>varargin</span>)<br>
<span class=h1>%&nbsp;DUALMEAN&nbsp;Computes&nbsp;dual&nbsp;representation&nbsp;of&nbsp;mean&nbsp;vector.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Synopsis:</span></span><br>
<span class=help>%&nbsp;&nbsp;m&nbsp;=&nbsp;dualmean(num_data)</span><br>
<span class=help>%&nbsp;&nbsp;m&nbsp;=&nbsp;dualmean(labels,y)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;<span class=help_field>Description:</span></span><br>
<span class=help>%&nbsp;&nbsp;This&nbsp;function&nbsp;computes&nbsp;a&nbsp;vector&nbsp;m&nbsp;which&nbsp;allows&nbsp;to&nbsp;express&nbsp;the&nbsp;mean</span><br>
<span class=help>%&nbsp;&nbsp;vector&nbsp;of&nbsp;data&nbsp;sample&nbsp;X&nbsp;[dim&nbsp;x&nbsp;num_data]&nbsp;in&nbsp;terms&nbsp;of&nbsp;dot&nbsp;products.&nbsp;</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;m&nbsp;=&nbsp;dualmean(num_data)&nbsp;computes&nbsp;a&nbsp;vector&nbsp;m&nbsp;[num_data&nbsp;x&nbsp;1]&nbsp;such&nbsp;that&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;mean(X,2)&nbsp;=&nbsp;X*m.</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;m&nbsp;=&nbsp;dualmean(labels,y)&nbsp;computes&nbsp;a&nbsp;vector&nbsp;m&nbsp;[length(y)&nbsp;x&nbsp;1]&nbsp;such&nbsp;that</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;&nbsp;mean(X(:,find(labels==y)),2)&nbsp;=&nbsp;X*m,</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;where&nbsp;labels&nbsp;[1&nbsp;x&nbsp;num_data]&nbsp;is&nbsp;a&nbsp;vector&nbsp;of&nbsp;data&nbsp;labels&nbsp;and&nbsp;&nbsp;y&nbsp;[1x1]&nbsp;&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;is&nbsp;a&nbsp;label&nbsp;od&nbsp;class&nbsp;which&nbsp;mean&nbsp;vector&nbsp;is&nbsp;to&nbsp;be&nbsp;computed.</span><br>
<span class=help>%&nbsp;</span><br>
<span class=help>%&nbsp;<span class=help_field>Example:</span></span><br>
<span class=help>%&nbsp;&nbsp;Unlabeled&nbsp;data:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;data&nbsp;=&nbsp;load('riply_trn');</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;ma&nbsp;=&nbsp;mean(&nbsp;data.X,&nbsp;2)</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;mb&nbsp;=&nbsp;data.X*dualmean(size(data.X,2))</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;&nbsp;Labeled&nbsp;data:</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;data&nbsp;=&nbsp;load('riply_trn');</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;ma1&nbsp;=&nbsp;mean(&nbsp;data.X(:,find(data.y==1)),2)</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;mb1&nbsp;=&nbsp;data.X*dualmean(data.y,1)</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;ma2&nbsp;=&nbsp;mean(&nbsp;data.X(:,find(data.y==2)),2)</span><br>
<span class=help>%&nbsp;&nbsp;&nbsp;mb2&nbsp;=&nbsp;data.X*dualmean(data.y,2)</span><br>
<span class=help>%</span><br>
<span class=help>%&nbsp;See&nbsp;also&nbsp;</span><br>
<span class=help>%&nbsp;&nbsp;DUALCOV.</span><br>
<span class=help>%</span><br>
<hr>
<span class=help1>%&nbsp;<span class=help1_field>About:</span>&nbsp;Statistical&nbsp;Pattern&nbsp;Recognition&nbsp;Toolbox</span><br>
<span class=help1>%&nbsp;(C)&nbsp;1999-2003,&nbsp;Written&nbsp;by&nbsp;Vojtech&nbsp;Franc&nbsp;and&nbsp;Vaclav&nbsp;Hlavac</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.cvut.cz"&gt;Czech&nbsp;Technical&nbsp;University&nbsp;Prague&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://www.feld.cvut.cz"&gt;Faculty&nbsp;of&nbsp;Electrical&nbsp;Engineering&lt;/a&gt;</span><br>
<span class=help1>%&nbsp;&lt;a&nbsp;href="http://cmp.felk.cvut.cz"&gt;Center&nbsp;for&nbsp;Machine&nbsp;Perception&lt;/a&gt;</span><br>
<br>
<span class=help1>%&nbsp;<span class=help1_field>Modifications:</span></span><br>
<span class=help1>%&nbsp;16-may-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;14-may-2004,&nbsp;VF</span><br>
<span class=help1>%&nbsp;22-Jan-2003,&nbsp;VF</span><br>
<span class=help1>%&nbsp;22-May-2001,&nbsp;V.&nbsp;Franc,&nbsp;created</span><br>
<br>
<hr>
<span class=keyword>if</span>&nbsp;<span class=stack>nargin</span>&nbsp;==&nbsp;2,<br>
&nbsp;&nbsp;<span class=comment>%&nbsp;labeled&nbsp;data</span><br>
&nbsp;&nbsp;labels&nbsp;=&nbsp;<span class=stack>varargin</span>{1};<br>
&nbsp;&nbsp;y&nbsp;=&nbsp;<span class=stack>varargin</span>{2};<br>
<br>
&nbsp;&nbsp;num_data&nbsp;=&nbsp;length(labels);<br>
&nbsp;&nbsp;m&nbsp;=&nbsp;zeros(num_data,1);<br>
&nbsp;&nbsp;inx&nbsp;=&nbsp;find(labels==y);<br>
&nbsp;&nbsp;m(inx)&nbsp;=&nbsp;ones(length(inx),1)/length(inx);<br>
<span class=keyword>else</span><br>
&nbsp;&nbsp;<span class=comment>%&nbsp;unlabeled&nbsp;data</span><br>
&nbsp;&nbsp;num_data&nbsp;=&nbsp;<span class=stack>varargin</span>{1};<br>
&nbsp;&nbsp;m&nbsp;=&nbsp;ones(num_data,1)/num_data;<br>
<span class=keyword>end</span><br>
<br>
<span class=jump>return</span>;<br>
<span class=comment>%&nbsp;EOF</span><br>
</code>
